import 'package:flutter/material.dart';
import 'dart:developer' as developer; // 导入 debugger()
// import 'package:http/http.dart' as http;

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text("调试示例")),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              ElevatedButton(
                onPressed: calculate,
                child: Text("触发计算（除以零错误）"),
              ),
              ElevatedButton(
                onPressed: fetchData,
                child: Text("获取网络数据"),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

// 计算函数（会触发除以零错误）
void calculate() {
  int a = 10;
  int b = 0;
  developer.debugger(); // 设置断点
  print("结果：${a / b}"); // 触发除以零错误
}

// 网络请求函数
void fetchData() async {
  try {
    final response = await http.get(Uri.parse("https://api.example.com/data"));
    print("响应状态码：${response.statusCode}");
  } catch (e) {
    print("请求失败：$e");
  }
}